/**
 * @file /include/rhzd_assist/qnode.hpp
 *
 * @brief Communications central!
 *
 * @date October 2025
 **/
/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef _QNODE_HPP_
#define _QNODE_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

// To workaround boost/qt4 problems that won't be bugfixed. Refer to
//    https://bugreports.qt.io/browse/QTBUG-22829
// #ifndef Q_MOC_RUN
// #include "rclcpp/rclcpp.hpp"
// #include <std_msgs/msg/float32.hpp>
// #endif
#include "rclcpp/rclcpp.hpp"
#include <std_msgs/msg/float32.hpp>
#include <string>
#include <QThread>
#include <QStringListModel>
#include <cv_bridge/cv_bridge.h>
#include <QImage>

#define QNODE_NAME "rhzd_assist"

enum class ImgPreviewType {
    NONE,
    RAW,
    DETPH,
};

/*****************************************************************************
** Class
*****************************************************************************/

class QNode : public QThread {
    Q_OBJECT
public:
	QNode(int argc, char** argv );
	virtual ~QNode();
	bool init();
	void run();
    int set_image_preview(bool flag);
    int set_image_preview(ImgPreviewType type);

Q_SIGNALS:
    void rosShutdown();
    void batteryState(double);
    void image_val(QImage);

public:
    rclcpp::Node::SharedPtr nh=nullptr;
    bool img_preview;
    int get_share_directory(QString &path);
    int get_config_directory(QString &path);

private:
	int init_argc;
	char** init_argv;
    rclcpp::Time img_update_time;
    int img_fps;
    float img_show_interval;
    ImgPreviewType img_preview_type;
    QString share_directory;
    rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr battery_sub;
    rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr img_sub;
    rclcpp::Subscription<sensor_msgs::msg::CompressedImage>::SharedPtr comp_img_sub;

private:
    void init_pubsub();
    void init_param();
    void batteryCallback(const std_msgs::msg::Float32::SharedPtr message);
    void image1_callback(const sensor_msgs::msg::Image::ConstSharedPtr msg);
    void image2_callback(const sensor_msgs::msg::CompressedImage &msg);
    QImage Mat2QImage(cv::Mat const& src);
};

#endif /* _QNODE_HPP_ */
